#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#使用π的莱布尼茨公式计算圆周率
from functools import reduce
import itertools

def pi(N):
    #原理：pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 ...
    odd = itertools.count(1, 2)
    lodd = itertools.takewhile(lambda x: x <= 2*N-1, odd)
    nums = itertools.cycle((4, -4))
    result = (next(nums) / i for i in lodd)
    return reduce(lambda x, y: x + y, result)

print(pi(1000000))